package com.tenghu.mysql.cus.controller;

import com.tenghu.mysql.cus.entity.CusBaseInfo;
import com.tenghu.mysql.cus.service.CusBaseInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
/**
 * 客户信息控制接口
 * Created by Arvin on 2017/12/8.
 */

@RestController
@RequestMapping(value = "/cus")
@Api(value = "客户信息控制接口",description = "客户信息控制接口")
public class CusBaseInfoController {

    @Autowired
    private CusBaseInfoService cusBaseInfoService;

    /**
     * 获取所有客户信息
     * @return
     */
    @RequestMapping(value = "/all",method = RequestMethod.GET)
    @ApiOperation(value = "获取所有客户信息",notes = "获取所有有效的客户信息")
    public List<CusBaseInfo> getAllCusBaseInfo(){
        return cusBaseInfoService.getAllCusBaseInfo();
    }

    /**
     * 保存客户信息
     * @param cusBaseInfo
     * @return
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @ApiOperation(value = "保存客户信息",notes = "保存客户信息")
    public CusBaseInfo saveCusBaseInfo(@ApiParam(value = "客户信息",name = "cusBaseInfo",required = true)  CusBaseInfo cusBaseInfo){
        return cusBaseInfoService.saveCusBaseInfo(cusBaseInfo);
    }

    /**
     * 根据客户ID查询客户信息
     * @param cusId
     * @return
     */
    @RequestMapping(value = "/get/{cusId}",method = RequestMethod.GET)
    @ApiOperation(value = "根据客户ID查询客户信息",notes = "根据客户ID查询客户信息")
    @ApiImplicitParam(paramType = "path",name = "cusId",value = "客户ID",required = true)
    public CusBaseInfo getCusBaseInfoById(@PathVariable  String cusId){
        return cusBaseInfoService.getCusBaseInfoById(cusId);
    }

    /**
     * 更新客户信息
     * @param cusBaseInfo 客户信息
     * @return
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ApiOperation(value = "更新客户信息",notes = "更新客户信息")
    public CusBaseInfo updateCusBaseInfo(@ApiParam(value = "客户信息",name = "cusBaseInfo",required = true) CusBaseInfo cusBaseInfo){
        return cusBaseInfoService.updateCusBaseInfo(cusBaseInfo);
    }

    /**
     * 删除客户信息
     * @param cusId 客户ID
     * @return
     */
    @RequestMapping(value = "/delete/{cusId}",method = RequestMethod.GET)
    @ApiOperation(value = "删除客户信息",notes = "根据客户ID删除客户信息")
    @ApiImplicitParam(paramType = "path",value = "客户ID",name = "cusId",required = true)
    public String deleteCusBaseInfo(@PathVariable("cusId") String cusId){
        int result=cusBaseInfoService.deleteCusBaseInfo(cusId);
        if(result>0){
            return "删除成功！";
        }
        return "删除失败！";
    }
}
